package com.mc.common.guava;

import org.junit.Test;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalTime;
import java.util.concurrent.*;

public class ExecutorTest {
    private final  static ExecutorService pool= Executors.newFixedThreadPool(2);

    @Test
    public void testExecutor() throws ExecutionException, InterruptedException {
        Future<Long> future = pool.submit(() -> {
            LocalTime now = LocalTime.now();
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            LocalTime end = LocalTime.now();
            return Duration.between(now, end).toMillis()/1000;
        });
        Long aLong = future.get();
        System.out.println("耗时"+aLong);
    }
}
